Skip to content

[build] JSG: store struct field wrappers in a flat array - #7249

Open
fhanau wants to merge 1 commit into
felix/081226-api-shrink-p0from
felix/081226-api-shrink-p1
Open

[build] JSG: store struct field wrappers in a flat array#7249
fhanau wants to merge 1 commit into
felix/081226-api-shrink-p0from
felix/081226-api-shrink-p1

Conversation

@fhanau

@fhanau fhanau commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Now that all of a struct's field wrappers hold nothing but an interned name, they no longer need to be distinct types. Move the field type from FieldWrapper's template arguments onto wrap()/unwrap() and keep the wrappers in a kj::Array instead of a kj::Tuple. Using an array allows us to avoid templating based on the list of nested ExpandAndApplyFunc types seen so far.

Field access stays direct: the fields pack still holds pointers to members, so in.*fields is a constant member offset, and the field type still comes from the pack via FieldType, so no dispatch becomes indirect.

================

Follow-up to #7248. This further reduces code size by reducing excessive template instantiations. Compile time (which I think people care about more) also improves. Part of a 3-part series to debloat workerd-api. Code changes made using an LLM, fully reviewed and edited by me.

No optimization, limited debug info, before change (i.e. with just #7248):

157725688 bazel-bin/external/+local_repository+workerd/src/workerd/server/_objs/workerd-api/workerd-api.pic.o
475323200 bazel-bin/external/+local_repository+workerd/src/workerd/server/workerd

No optimization, limited debug info, after:

144582640 bazel-bin/external/+local_repository+workerd/src/workerd/server/_objs/workerd-api/workerd-api.pic.o
462260488 bazel-bin/external/+local_repository+workerd/src/workerd/server/workerd

When compiling server directory with -O3, before:

 90612616 bazel-bin/external/+local_repository+workerd/src/workerd/server/_objs/workerd-api/workerd-api.pic.o
414583536 bazel-bin/external/+local_repository+workerd/src/workerd/server/workerd

When compiling server directory with -O3, after:

-r-xr-xr-x 1 root root  83527856 Sep  4 14:07 bazel-bin/external/+local_repository+workerd/src/workerd/server/_objs/workerd-api/workerd-api.pic.o
-r-xr-xr-x 1 root root 407549208 Sep  4 14:07 bazel-bin/external/+local_repository+workerd/src/workerd/server/workerd

Now that all of a struct's field wrappers hold nothing but an interned name,
they no longer need to be distinct types. Move the field type from
FieldWrapper's template arguments onto wrap()/unwrap() and keep the wrappers in
a kj::Array instead of a kj::Tuple. Using an array allows us to avoid templating
based on the list of nested ExpandAndApplyFunc types seen so far.

Field access stays direct: the `fields` pack still holds pointers to members, so
`in.*fields` is a constant member offset, and the field type still comes from
the pack via FieldType, so no dispatch becomes indirect.
@fhanau
fhanau requested review from dcarney-cf and jasnell September 4, 2026 14:24
@fhanau
fhanau requested review from a team as code owners September 4, 2026 14:24
@ask-bonk

ask-bonk Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

LGTM

github run

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants